package com.coollang.smartbra.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;

import com.coollang.smartbra.activity.ActionDetailActivity;
import com.coollang.smartbra.fragment.ChangePassFragment;
import com.coollang.smartbra.fragment.LoginBaseFragment;
import com.coollang.smartbra.fragment.LoginFragment;
import com.coollang.smartbra.fragment.RegistFragment;

public class LoginPagerAdapter extends FragmentStatePagerAdapter {
    // 缓存所有的fragment对象
    //public HashMap<Integer, LoginBaseFragment> mFragmentMap = new HashMap<>();
    private LoginBaseFragment mBaseFragment;

    public LoginPagerAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int position) {
        // mBaseFragment = mFragmentMap.get(position);
        mBaseFragment = null;
        if (mBaseFragment == null) {
            switch (position) {
                case 0:
                    mBaseFragment = new RegistFragment();
                    break;
                case 1:
                    mBaseFragment = new LoginFragment();
                    break;
                case 2:
                    mBaseFragment = new ChangePassFragment();
                    break;
                default:
            }
            // mFragmentMap.put(position, mBaseFragment);
        }
        return mBaseFragment;
    }

    @Override
    public int getCount() {
        return 3;
    }

    public LoginBaseFragment getBaseFragment() {
        return mBaseFragment;
    }
}
